/**
 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.library.slayer.model.impl;

import com.library.slayer.model.Book;
import com.library.slayer.model.BookModel;
import com.library.slayer.model.BookSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the Book service. Represents a row in the &quot;library_Book&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.library.slayer.model.BookModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link BookImpl}.
 * </p>
 *
 * <p>
 * Never modify or reference this class directly. All methods that expect a book model instance should use the {@link com.library.slayer.model.Book} interface instead.
 * </p>
 *
 * @author Ahmed Hasan
 * @see BookImpl
 * @see com.library.slayer.model.Book
 * @see com.library.slayer.model.BookModel
 * @generated
 */
public class BookModelImpl extends BaseModelImpl<Book> implements BookModel {
	public static final String TABLE_NAME = "library_Book";
	public static final Object[][] TABLE_COLUMNS = {
			{ "bookId", new Integer(Types.BIGINT) },
			{ "bookTitle", new Integer(Types.VARCHAR) },
			{ "author", new Integer(Types.VARCHAR) },
			{ "dateAdded", new Integer(Types.TIMESTAMP) },
			{ "dateModified", new Integer(Types.TIMESTAMP) }
		};
	public static final String TABLE_SQL_CREATE = "create table library_Book (bookId LONG not null primary key IDENTITY,bookTitle VARCHAR(75) null,author VARCHAR(75) null,dateAdded DATE null,dateModified DATE null)";
	public static final String TABLE_SQL_DROP = "drop table library_Book";
	public static final String ORDER_BY_JPQL = " ORDER BY book.bookTitle ASC, book.author DESC";
	public static final String ORDER_BY_SQL = " ORDER BY library_Book.bookTitle ASC, library_Book.author DESC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.library.slayer.model.Book"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.library.slayer.model.Book"),
			true);

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Book toModel(BookSoap soapModel) {
		Book model = new BookImpl();

		model.setBookId(soapModel.getBookId());
		model.setBookTitle(soapModel.getBookTitle());
		model.setAuthor(soapModel.getAuthor());
		model.setDateAdded(soapModel.getDateAdded());
		model.setDateModified(soapModel.getDateModified());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Book> toModels(BookSoap[] soapModels) {
		List<Book> models = new ArrayList<Book>(soapModels.length);

		for (BookSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.library.slayer.model.Book"));

	public BookModelImpl() {
	}

	public long getPrimaryKey() {
		return _bookId;
	}

	public void setPrimaryKey(long pk) {
		setBookId(pk);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_bookId);
	}

	public long getBookId() {
		return _bookId;
	}

	public void setBookId(long bookId) {
		_bookId = bookId;
	}

	public String getBookTitle() {
		if (_bookTitle == null) {
			return StringPool.BLANK;
		}
		else {
			return _bookTitle;
		}
	}

	public void setBookTitle(String bookTitle) {
		_bookTitle = bookTitle;

		if (_originalBookTitle == null) {
			_originalBookTitle = bookTitle;
		}
	}

	public String getOriginalBookTitle() {
		return GetterUtil.getString(_originalBookTitle);
	}

	public String getAuthor() {
		if (_author == null) {
			return StringPool.BLANK;
		}
		else {
			return _author;
		}
	}

	public void setAuthor(String author) {
		_author = author;

		if (_originalAuthor == null) {
			_originalAuthor = author;
		}
	}

	public String getOriginalAuthor() {
		return GetterUtil.getString(_originalAuthor);
	}

	public Date getDateAdded() {
		return _dateAdded;
	}

	public void setDateAdded(Date dateAdded) {
		_dateAdded = dateAdded;
	}

	public Date getDateModified() {
		return _dateModified;
	}

	public void setDateModified(Date dateModified) {
		_dateModified = dateModified;
	}

	public Book toEscapedModel() {
		if (isEscapedModel()) {
			return (Book)this;
		}
		else {
			return (Book)Proxy.newProxyInstance(Book.class.getClassLoader(),
				new Class[] { Book.class }, new AutoEscapeBeanHandler(this));
		}
	}

	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					Book.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	public Object clone() {
		BookImpl clone = new BookImpl();

		clone.setBookId(getBookId());
		clone.setBookTitle(getBookTitle());
		clone.setAuthor(getAuthor());
		clone.setDateAdded(getDateAdded());
		clone.setDateModified(getDateModified());

		return clone;
	}

	public int compareTo(Book book) {
		int value = 0;

		value = getBookTitle().compareTo(book.getBookTitle());

		if (value != 0) {
			return value;
		}

		value = getAuthor().compareTo(book.getAuthor());

		value = value * -1;

		if (value != 0) {
			return value;
		}

		return 0;
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Book book = null;

		try {
			book = (Book)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long pk = book.getPrimaryKey();

		if (getPrimaryKey() == pk) {
			return true;
		}
		else {
			return false;
		}
	}

	public int hashCode() {
		return (int)getPrimaryKey();
	}

	public String toString() {
		StringBundler sb = new StringBundler(11);

		sb.append("{bookId=");
		sb.append(getBookId());
		sb.append(", bookTitle=");
		sb.append(getBookTitle());
		sb.append(", author=");
		sb.append(getAuthor());
		sb.append(", dateAdded=");
		sb.append(getDateAdded());
		sb.append(", dateModified=");
		sb.append(getDateModified());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(19);

		sb.append("<model><model-name>");
		sb.append("com.library.slayer.model.Book");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>bookId</column-name><column-value><![CDATA[");
		sb.append(getBookId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>bookTitle</column-name><column-value><![CDATA[");
		sb.append(getBookTitle());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>author</column-name><column-value><![CDATA[");
		sb.append(getAuthor());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>dateAdded</column-name><column-value><![CDATA[");
		sb.append(getDateAdded());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>dateModified</column-name><column-value><![CDATA[");
		sb.append(getDateModified());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _bookId;
	private String _bookTitle;
	private String _originalBookTitle;
	private String _author;
	private String _originalAuthor;
	private Date _dateAdded;
	private Date _dateModified;
	private transient ExpandoBridge _expandoBridge;
}